package com.chinairi.mall.controller;


import com.chinairi.common.utils.ResponseUtil;
import com.chinairi.mall.controller.viewobject.ContractMaintainGetVO;
import com.chinairi.mall.controller.viewobject.ContractMaintainVO;
import com.chinairi.mall.service.IContractMaitainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import com.chinairi.common.controller.BaseController;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 合同维护 前端控制器
 * </p>
 *
 * @author Webgasd
 * @since 2020-09-03
 */
@RestController
@RequestMapping("/contract-maitain")
public class ContractMaitainController extends BaseController {
    @Autowired
    private IContractMaitainService iContractMaitainService;

    /**
     * 根据企业资质类型获取企业dbid
     * @param type
     * @throws IOException
     */
    @GetMapping("/getCompDbIdList")
    @ResponseBody
    public void getCompDbIdList(Integer type) throws IOException {
        ResponseUtil.showMessage("success","企业列表获取成功", iContractMaitainService.getCompDbIdList(type));
    }

    @PostMapping("/config")
    @ResponseBody
    public void config(@RequestBody ContractMaintainVO contractMaintainVO) throws IOException {
        iContractMaitainService.config(contractMaintainVO);
        ResponseUtil.showMessage("success","合同添加成功", null);
    }

    @GetMapping("/getByUuid")
    @ResponseBody
    public void getByUuid(String uuid) throws IOException {
        ResponseUtil.showMessage("success","合同内容获取成功", iContractMaitainService.getByUuid(uuid));
    }

    @PutMapping("/update")
    @ResponseBody
    public void update(@RequestBody ContractMaintainVO contractMaintainVO) throws IOException {
        iContractMaitainService.update(contractMaintainVO);
        ResponseUtil.showMessage("success","合同更新成功", null);
    }

    @DeleteMapping("/delete")
    @ResponseBody
    public void delete(String uuid) throws IOException {
        iContractMaitainService.deleteById(uuid);
        ResponseUtil.showMessage("success","删除合同成功!", null);
    }

    @GetMapping("/get")
    @ResponseBody
    public void getList(ContractMaintainGetVO contractMaintainGetVO) throws IOException {
        List<ContractMaintainGetVO> list =iContractMaitainService.get(contractMaintainGetVO);
        ResponseUtil.showMessage("success","合同列表", list);
    }

}
